<?php
require_once('wpfunctions.php');
header("Content-type: application/json");
$root = 'verses';

$result = array();
foreach(ip_allFiles($root) as $dir) {
  if(is_dir($dir)) {
    foreach(ip_scandir($dir) as $v) {
      if(is_dir("$dir/$v") && !preg_match('/^\.|^\.{1,2}$/',$v)) {
        $tmp = array();
        $subentries = ip_scandir("$dir/$v");
        foreach($subentries as $subv) {
          if(is_dir("$dir/$v/$subv") && !preg_match('/^\.|^\.{1,2}$/',$subv)) {
            $tmp[] = $subv;
          }
        }
        if(count($tmp)==0) {
          $tmp[] = '';
        }
        $result[$v] = $tmp;
      }
    }
  }
}
echo json_encode($result);
?>